/**
 * Created with IntelliJ IDEA.
 * Date: 19.09.13
 * Time: 22:30
 */
package module1.longdivision;

import java.util.Scanner;

/**
 * The Class Division provides division of integer numbers and displaying long division (division in a column).
 * Conditions:
 * - the dividend more than the divisor
 * - the divisor can not be zero.
 * - works with negative numbers.
 *
 * @author Anzhela Petrovska
 */
public class Division {
    private static final int BASE = 10;

    /**
     * Main method: create instance of the class, invocation of simple menu method
     */
    public static void main(String args[]) {
        startMenu();
    }

    /**
     * The method used as simple startMenu to choice desired action: exit or continue
     * Case structure allows future modifications and additions for the startMenu
     */
    private static void startMenu() {
        int menuOptionId = getMenuOptionId();

        switch (menuOptionId) {
            case 1:
                getInputData();


                break;
            case 0:
                System.out.println("Exit");
                System.exit(0);
                break;
            default:
                System.out.println("No such id of action");
                startMenu();
        }
    }

    /**
     * The method used for verification of input data for method startMenu()
     * Functional description:
     * - user must enter numeric value
     * - in other case,appears error message
     * - possibility of re-input data without exit or re-start program
     *
     * @return int value
     */
    private static int getMenuOptionId() {
        System.out.println("\nEnter:\n0 - for exit\n1 - to continue");
        Scanner scanner = new Scanner(System.in);
        int optionId = 0;

        if (scanner.hasNextInt()) {
            optionId = scanner.nextInt();
        } else {
            System.out.println("Error! It is not a correct value");
            startMenu();
        }
        return optionId;
    }


    /**
     * The method used for getting dividend and divisor from the console and invocation method for  verification of input data
     */
    private static void getInputData() {
        Scanner scanner = new Scanner(System.in);
        int dividend = getValue(scanner, "Enter dividend");
        int divisor = getValue(scanner, "Enter divisor(less than dividend and not 0)");

        if (checkInputData(dividend, divisor)) {
            divideIntegerNumbers();
        } else {
            System.out.println("Error! Enter correct data");
            getInputData();
        }
        scanner.close();
    }

    private static int getValue(Scanner scanner, String message) {
        System.out.println(message);
        return scanner.nextInt();
    }

    /**
     * The method used for verification the input data: divisor not zero and divisor less than dividend
     *
     * @return true if input data meet needed conditions
     */
    private static boolean checkInputData(int dividendValue, int divisorValue) {
        boolean check = true;
        if (divisorValue == 0) {
            check = false;
        }
        if (getLength(dividendValue) < getLength(divisorValue)) {
            check = false;
        }
        return check;
    }

    /**
     * The method used to get quantity of digits of number
     *
     * @param number - is number for calculation
     * @return length (quantity of digits) of number
     */
    private static int getLength(int number) {
        return Integer.toString(number).length();
    }

    private static void divideIntegerNumbers() {
        // realization of method
        startMenu();
    }

    private static void printDivision() {
        // realization of method
    }

    private static void getDigitsOfDividend(int dividend) {
        int lenghtOfDividend = getLength(dividend);
        int[] digitsOfDividend = new int[lenghtOfDividend];

        for (int i = 0; lenghtOfDividend < 0; i++) {
            digitsOfDividend[i] = dividend % BASE;
            dividend /= BASE;
        }

    }
}
